/* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements.  See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License.  You may obtain a copy of the License at
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/


/*************************************************************************
 * File: codec/python.hpp
 *************************************************************************
 *\author: starlove
 *************************************************************************/

#ifndef __CC_PYTHON_PYTHONCODEC_H__
#define __CC_PYTHON_PYTHONCODEC_H__

#ifdef _DEBUG
#undef _DEBUG
#define DEBUG_FLAG_OPEN
#endif // _DEBUG

#include <Python.h>

#ifdef DEBUG_FLAG_OPEN
#define _DEBUG
#undef DEBUG_FLAG_OPEN
#endif // DEBUG_FLAG_OPEN

#include "../codec.hpp"
#include "../data.hpp"
#include <python_import_macro.h>

NS_CCPY_BEGIN

    class CPythonEncoder : public IEncoder
    {
        public:
            virtual bool Encode(IAutoExpandBuffer *, void *);
            virtual bool Encode(IData *, void *);
        protected:
            bool EncodeMapData(IAutoExpandBuffer *, PyObject *);
            bool EncodeListData(IAutoExpandBuffer *, PyObject *);
        private:
			CODEC_BUFFER m_tmpBuffer;
    };

    class CPythonDecoder : public IDecoder
    {
        public:
            virtual bool Decode(CBufferReader *, void *);
            virtual bool Decode(IData *, void *);
    };

    class CPythonCodec : public ICodec
    {
        public:
            virtual LPIEncoder GetEncoder();
            virtual LPIDecoder GetDecoder();
        protected:
        private:
            CPythonEncoder m_encoder;
            CPythonDecoder m_decoder;
    };
	
NS_CCPY_END

#endif //__CC_PYTHON_PYTHONCODEC_H__
